package com.fh.modules.dbms.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fh.common.util.StringUtils;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @Author qiujunda
 * @Date 14/07/2020
 * @Description
 */
@Data
@TableName("dbms_table_column")
public class DbmsTableColumn implements Serializable {
    private static final long serialVersionUID = 100230L;

    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    private Long tableId;

    private Integer columnId;

    private String columnName;

    private String nullable;

    private String dataType;

    private Integer dataLength;

    private Integer dataPrecision;

    private String columnComments;


    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    private Integer delFlag;

    private String collectSid;

    public boolean equals(DbmsTableColumn dbmsTableColumn) {
        if (this.getColumnName().equals(dbmsTableColumn.getColumnName()) &&
                StringUtils.compareStr(this.getColumnComments(), dbmsTableColumn.getColumnComments()) &&
                StringUtils.compareStr(this.getDataType(), dbmsTableColumn.getDataType()) &&
                StringUtils.compareStr(this.getNullable(), dbmsTableColumn.getNullable()) &&
                this.getDataLength().intValue() == dbmsTableColumn.getDataLength().intValue()) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "表字段{" +
                "字段名='" + columnName + '\'' +
                ", null='" + nullable + '\'' +
                ", 类型='" + dataType + '\'' +
                ", 长度=" + dataLength +
                ", 精度=" + dataPrecision +
                ", 注释='" + columnComments + '\'' +
                '}';
    }
}
